package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.clue.ClueConvertToFalseClueDTO;
import com.qk.dto.clue.ClueFollowUpDTO;
import com.qk.dto.clue.ClueInsertDTO;
import com.qk.dto.clue.CluePageDTO;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.ClueByIdVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 上官徵羽
 * @version 1.0
 * @since 2025-10-12 21:55
 */
@Slf4j
@RestController
@RequestMapping("/clues")
public class ClueController {
    @Autowired
    private ClueService clueService;

    @GetMapping
    public Result listPage(CluePageDTO cluePageDTO){
        return Result.success(clueService.listPage(cluePageDTO));
    }
    @LogAnno
    @PostMapping
    public Result save(ClueInsertDTO clueInsertDTO){
        clueService.save(clueInsertDTO);
        return Result.success();
    }
    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result assign(@PathVariable Integer clueId,@PathVariable Integer userId){
        clueService.assignLeads(clueId, userId);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueById(@PathVariable Integer id){
        ClueByIdVO clueByIdVO = clueService.getClueById(id);
        return Result.success(clueByIdVO);
    }

    @LogAnno
    @PutMapping
    public Result clueFollowUpUpdateAndInsertById(@RequestBody ClueFollowUpDTO clueFollowUpDTO){
        clueService.clueFollowUpUpdateAndInsertById(clueFollowUpDTO);
        return Result.success();
    }
    @LogAnno
    @PutMapping("/toBusiness/{id}")
    public Result clueConvertToBusiness(@PathVariable Integer id){
        clueService.clueConvertToBusiness(id);
        return Result.success();
    }
    @LogAnno
    @PutMapping("/false/{id}")
    public Result clueConvertToFalseClue(@PathVariable Integer id,@RequestBody ClueConvertToFalseClueDTO clueConvertToFalseClueDTO){
        clueService.clueConvertToFalseClue(id, clueConvertToFalseClueDTO);
        return Result.success();
    }

    @GetMapping("/pool")
    public Result getCluePool(CluePageDTO cluePageDTO){
        return Result.success(clueService.getCluePool(cluePageDTO));
    }
}
